//引入
const express = require("express")

//创建路由
const route = express.Router()

// 引入token校验中间件
const isLoginMiddle = require("../middleware/isLoginMiddle")

//引用数据库集合模块
const adminModel = require("../db/model/adminModel")

//引入jwt中的jwtDecode解码方法
const {
    jwtDecode
} = require("../utils/jwt")



//设置登录路由
route.get("/outLogin", isLoginMiddle, async (req, res) => {
    const {
        token
    } = req.headers
    // console.log(adminName, password);
    // 解码token
    const {
        adminName,
    } = jwtDecode(token, "18069277360")

    try {
        await adminModel.updateOne({
            adminName
        }, {
            $set: {
                status: 0
            }
        })

        res.send({
            code: 10000,
            msg: "退出成功",
            data: null
        })
    } catch (e) {
        console.log("退出登录出现异常" + e.message);
        res.send({
            code: 10001,
            msg: "退出登录出现异常" + e.message,
            data: null
        })
    }


})

//暴露
module.exports = route